<?php
/**
 * TomatoCMS
 *
 * LICENSE
 *
 * This source file is subject to the GNU GENERAL PUBLIC LICENSE Version 2
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://www.gnu.org/licenses/gpl-2.0.txt
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@tomatocms.com so we can send you a copy immediately.
 *
 * @copyright    Copyright (c) 2009-2010 TIG Corporation (http://www.tig.vn)
 * @license        http://www.gnu.org/licenses/gpl-2.0.txt GNU GENERAL PUBLIC LICENSE Version 2
 * @version     $Id: edit.phtml 3275 2010-06-04 09:19:41Z huuphuoc $
 */
?>
<?php
$this->headTitle($this->translator('attribute_edit_page_title'));
$this->headLink()
    ->appendStylesheet($this->APP_STATIC_SERVER . '/js/jquery.ui/themes/base/ui.all.css')
    ;

$this->headScript()
    ->appendFile($this->APP_STATIC_SERVER . '/js/jquery.validate/jquery.validate.min.js')
    ;
?>

<div class="grid_12 t_a_ui_breadcrumb">
    <span><a href="<?php echo $this->url(array(), 'attribute_attribute_list'); ?>"><?php echo $this->translator('attribute_list_breadcump'); ?></a></span>
    <span><?php echo $this->translator('attribute_edit_breadcump'); ?></span>
</div>

<div class="grid_12"><?php echo $this->flashMessenger(); ?></div>

<!--Begin attribute basic info-->
<form method="post" action="<?php echo $this->url(array('attribute_id' => $this->attribute->attribute_type_id), 'attribute_attribute_edit'); ?>" id="editAttributeForm">
<div>&nbsp;</div>
<div class="grid_12 t_a_bottom" style="font-size:13px; font-weight:bold">1. <?php echo $this->translator('attribute_basic_guide'); ?></div>
<div class="grid_12"><hr /></div>

<div class="grid_12 t_a_bottom">
    <div class="prefix_1 suffix_1">
        <div class="clearfix t_a_bottom">
            <label><?php echo $this->translator('attribute_type_admin_name'); ?>:</label>
            <input type="text" id="attribute_type_admin_name" name="attribute_type_admin_name" value="<?php if ($this->attribute != null) : ?><?php echo $this->attribute->attribute_type_admin_name; ?><?php endif; ?>" style="width: 300px" />
        </div>

        <hr/>

        <div class="clearfix t_a_bottom">
            <label><?php echo $this->translator('attribute_category_name'); ?>:</label>
            <div style="border:1px solid #CCC; padding: 5px; width:300px;overflow:auto;height:120px">
                <?php for ($i = 0; $i < count($this->categories); $i++) : ?>
                    <input type="checkbox" <?php if(strstr($this->attribute->category_id,','.$this->categories[$i]->category_id.',')):?>checked="checked"<?php endif;?> id="category_id[]" name="category_id[]" value="<?php echo $this->categories[$i]->category_id; ?>"> <?php echo str_repeat('---', $this->categories[$i]->depth).$this->categories[$i]->category_admin_name; ?><br>
                <?php endfor; ?>
            </div>
        </div>

        <hr/>

        <div class="clearfix t_a_bottom">
            <label>&nbsp;</label>
            <button type="submit"><span><?php echo $this->translator('attribute_add_save_button'); ?></span></button>
        </div>
    </div>
</div>
</form>
<!--End attribute basic info-->

<?php $arrAttributeContent = $this->arrAttributeContent?>
<div class="grid_12 t_a_bottom" style="font-size:13px; font-weight:bold">2. <?php echo $this->translator('attribute_content_guide'); ?></div>
<div class="grid_12"><hr/></div>
<!--Begin attribute content-->
<?php foreach ($this->languages as $language) : ?>
<form method="post" action="<?php echo $this->url(array('attribute_id' => $this->id), 'attribute_attribute_edit_content'); ?>" id="editAttributeContentForm_<?php echo $language->language_code;?>">
<div class="grid_12 t_a_bottom">
    <div class="prefix_1 suffix_1">
        <input type="hidden" id="attribute_type_content_id" name="attribute_type_content_id" value="<?php echo isset($arrAttributeContent[$language->language_code]->attribute_type_content_id)?$arrAttributeContent[$language->language_code]->attribute_type_content_id:null;?>" />
        <div class="clearfix t_a_bottom">
            <?php echo $this->translator('attribute_language_guide'); ?> <strong><?php echo $language->language_name;?></strong>
            <input type="hidden" id="language_code" name="language_code" value="<?php echo $language->language_code;?>" />
        </div>

        <hr/>

        <div class="clearfix t_a_bottom">
            <label><?php echo $this->translator('attribute_type_content_name'); ?>:</label>
            <input value="<?php echo isset($arrAttributeContent[$language->language_code]->attribute_type_content_name)?$arrAttributeContent[$language->language_code]->attribute_type_content_name:null;?>" type="text" id="attribute_type_content_name" name="attribute_type_content_name" style="width: 300px" />
        </div>

        <hr/>

        <div class="clearfix t_a_bottom">
            <label><?php echo $this->translator('attribute_type_content_description'); ?>:</label>
            <textarea id="attribute_type_content_description" name="attribute_type_content_description" style="width: 300px; height: 100px;"><?php echo isset($arrAttributeContent[$language->language_code]->attribute_type_content_description)?$arrAttributeContent[$language->language_code]->attribute_type_content_description:null;?></textarea>
        </div>

        <hr/>

        <div class="clearfix t_a_bottom">
            <label>&nbsp;</label>
            <button type="submit"><span><?php echo $this->translator('attribute_add_save_button'); ?></span></button>
        </div>
    </div>
</div>
</form>
<!--End attribute content-->

<script type="text/javascript">
$(document).ready(function() {
    $('#editAttributeContentForm_<?php echo $language->language_code;?>').validate({
        rules: {
            attribute_type_content_name: {
                required: true,
                maxlength: 255
            }
        },
        messages: {
            attribute_type_content_name: {
                required: "<?php echo $this->translator('attribute_content_name_required'); ?>",
                maxlength: "<?php echo $this->translator('attribute_name_maxlength'); ?>"
            }
        }
    });
});
</script>
<?php endforeach; ?>

<script type="text/javascript">
$(document).ready(function() {

    $('#editAttributeForm').validate({
        rules: {
            attribute_type_admin_name: {
                required: true,
                maxlength: 255
            },
            "category_id[]": "required"
        },
        messages: {
            attribute_type_admin_name: {
                required: "<?php echo $this->translator('attribute_name_required'); ?>",
                maxlength: "<?php echo $this->translator('attribute_name_maxlength'); ?>"
            },
            "category_id[]": "<?php echo $this->translator('attribute_category_id_required'); ?>"
        }
    });
});
</script>
